#ifndef SCENE_H
#define SCENE_H

#include <list>
#include "Triangle.h"
#include "Octree.h"
#include "Camera.h"

extern Camera camera;

using namespace std;

class Scene
{
protected:
    list<Triangle *> shapes;
	Octree *oct;

public:
	Scene()
	{
		shapes.clear();
		oct = 0;
	}
    ~Scene()
    {
        Erase();
    }
    void Erase()
    {
        for (list<Triangle*>::iterator iter = shapes.begin();
             iter != shapes.end();)
        {
            delete (*iter);
            iter = shapes.erase(iter);
        }
    }
	void ProcessOctree(float fovy, float aspect)
	{
		if(oct)
			delete oct;
		oct = new Octree(shapes, fovy, aspect, 5);
	}
    /*void Get(list<Triangle*>* octreeShapes)
    {
		vec<float, 3> right; right = camera.face.cross(camera.up);
		right = right.normalize();
		oct->ReturnVisibleShapesFrustrum(octreeShapes, camera.loc[0], camera.loc[1], camera.loc[2], camera.face[0], camera.face[1], camera.face[2], camera.up[0], camera.up[1], camera.up[2], right[0], right[1], right[2]);
    }*/
	void GetSphere(list<Triangle*>* sphereShapes, float radius)
    {
		oct->ReturnVisibleShapesSphere(sphereShapes, camera.loc[0], camera.loc[1], camera.loc[2], radius);
    }
    void Get(list<GLuint>* callLists)
    {
		vec<float, 3> right; right = camera.face.cross(camera.up);
		oct->ReturnVisibleShapesCallList(callLists, camera.loc[0], camera.loc[1], camera.loc[2], camera.face[0], camera.face[1], camera.face[2], camera.up[0], camera.up[1], camera.up[2], right[0], right[1], right[2]);
		cout << callLists->size() << "\n";
    }
    virtual void Build() = 0;
};

#endif